<?php
/**
 * @desc
 * @author: jintao
 * @since: 2016/7/20
 */
class erpapi_shop_matrix_taobao_response_aftersalev2 extends erpapi_shop_response_aftersalev2 {

    protected function _formatAddParams($params) {
        $sdf = parent::_formatAddParams($params);
        if($params['tag_list']) {
            $tagList = json_decode($params['tag_list'], true);
            $tagList = serialize($tagList);
        }
        $taobaoSdf = array(
            'oid'               => $params['oid'],
            'cs_status'         => $params['cs_status'],
            'advance_status'    => $params['advance_status'],
            'split_taobao_fee'  => $params['split_taobao_fee'],
            'split_seller_fee'  => $params['split_seller_fee'],
            'total_fee'         => $params['total_fee'],
            'seller_nick'       => $params['seller_nick'],
            'good_status'       => $params['good_status'],
            'current_phase_timeout'=>strtotime($params['current_phase_timeout']),
            'ship_addr'         => $params['receiver_address'],
            'tag_list'          => $tagList ? $tagList : '',
            'address'           => $params['address'] ? $params['address'] : '',
            't_ready'           =>$sdf['t_begin'],
            't_sent'           =>$sdf['modified'],
            't_received'       =>''
        );
        return array_merge($sdf, $taobaoSdf);
    }

    protected function _getAddType($sdf) {
        if ($sdf['has_good_return'] == 'true') {//需要退货才更新为售后单
            if (in_array($sdf['order']['ship_status'],array('0'))) {
                #有退货，未发货的,做退款
                return 'refund';
            }else{
                #有退货，已发货的,做售后
                return 'returnProduct';
            }
        }else{
            #无退货的，直接退款
            return 'refund';
        }
    }

    protected function _formatAddItemList($sdf, $convert=array()) {
        $convert = array(
            'sdf_field'=>'oid',
            'order_field'=>'oid',
            'default_field'=>'outer_id'
        );
        return parent::_formatAddItemList($sdf, $convert);
    }

    protected function _refundApplyAdditional($sdf) {
        $ret = array(
            'model' => 'refund_apply_taobao',
            'data' => array(
                'shop_id'           => $sdf['shop_id'],
                'oid'               => $sdf['oid'],
                'cs_status'         => $sdf['cs_status'],
                'advance_status'    => $sdf['advance_status'],
                'split_taobao_fee'  => $sdf['split_taobao_fee'],
                'split_seller_fee'  => $sdf['split_seller_fee'],
                'total_fee'         => $sdf['total_fee'],
                'seller_nick'       => $sdf['seller_nick'],
                'good_status'       => $sdf['good_status'],
                'has_good_return'   => $sdf['has_good_return'],
                'alipay_no'         => $sdf['alipay_no'],
                'current_phase_timeout'=>$sdf['current_phase_timeout'],
            )
        );
        return $ret;
    }

    protected function _returnProductAdditional($sdf) {
        $ret = array(
            'model' => 'return_product_taobao',
            'data' => array(
                'shop_id'         => $sdf['shop_id'],
                'shipping_type'   => $sdf['shipping_type'],
                'cs_status'       => $sdf['cs_status'],
                'advance_status'  => $sdf['advance_status'],
                'split_taobao_fee'=> $sdf['split_taobao_fee'],
                'split_seller_fee'=> $sdf['split_seller_fee'],
                'total_fee'       => $sdf['total_fee'],
                'buyer_nick'      => $sdf['buyer_nick'],
                'seller_nick'     => $sdf['seller_nick'],
                'good_status'     => $sdf['good_status'],
                'has_good_return' => $sdf['has_good_return'],
                'good_return_time'=> $sdf['good_return_time'],
                'alipay_no'       => $sdf['alipay_no'],
                'ship_addr'       => $sdf['receiver_address'],
                'outer_lastmodify'=> $sdf['modified'],
                'oid'             => $sdf['oid'],
                'current_phase_timeout'=>$sdf['current_phase_timeout'],
                'tag_list'        => $sdf['tag_list'],
                'address'         => $sdf['address']
            )
        );
        return $ret;
    }
}
